package com.yanqu.road.server.logic.activity.condition.apprentice;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.apprentice.ApprenticeModule;
import com.yanqu.road.server.gameplayer.module.activity.yuanbaolottery.YuanBaoLotteryModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;

import java.math.BigInteger;
import java.util.List;

public class ApprenticeTalentAmountCondition extends BaseActivityCondition {
    public ApprenticeTalentAmountCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int round = player.getModule(YuanBaoLotteryModule.class).getRound();
        int checkRound = activityConditionInfo.getParamList().get(2).intValue();
        if (round != checkRound) {
            return;
        }

        List<Long> args = (List<Long>) object;
        int mallShopType = args.get(0).intValue();
        long talentValueAdd = args.get(1);

        int checkShopType = activityConditionInfo.getParamList().get(0).intValue();
        if (mallShopType != checkShopType) {
            return;
        }
        BigInteger newValue = getValue().add(BigInteger.valueOf(talentValueAdd));
        setValue(newValue);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ApprenticeTalentAmount.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ApprenticeTalentAmount.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        int round = player.getModule(YuanBaoLotteryModule.class).getRound();
        int checkRound = activityConditionInfo.getParamList().get(2).intValue();
        if (round != checkRound) {
            return false;
        }
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo) {
        return ActivityMgr.activityInTime(activityInfo);
    }
}
